# задача для создания микросервисов сделать классы
import requests
from config import API_price


class Statistics:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = 'https://statistics-api.wildberries.ru'
        self.headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + self.api_key}

    def orders(self, date_start):
        param = {'dateFrom': date_start}
        response_1 = requests.get(f'{self.base_url}/api/v1/supplier/orders', headers=self.headers,
                                  params=param)
        orders_data = response_1.json()
        return orders_data

    def sales(self, date_start):
        param = {'dateFrom': date_start}
        response_1 = requests.get(f'{self.base_url}/api/v1/supplier/sales', headers=self.headers,
                                  params=param)
        sales_data = response_1.json()
        return sales_data


# это другой класс типо Marcetplace()
class ListOfGoods:  # Класс ЦЕНЫ И СКИДКИ, потом другой клас МАРКЕТПЛЕЙС, потом другой класс КОНТЕНТ
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = 'https://discounts-prices-api.wb.ru'
        self.headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + self.api_key}

    def get_product_stock(self, limit):
        url = f'{self.base_url}/api/v2/list/goods/filter'
        data = {'limit': limit}
        response = requests.get(url, headers=self.headers, params=data)
        # print(response)
        if response.status_code == 200:
            data = response.json()
            # print(data)
            return data
        else:
            print(f'Error: Unable to retrieve stock for product ID')
            return None

    # def get_product_sizes(self, nm):
    #     url = f'{self.base_url}/api/v2/list/goods/size/nm'
    #     data = {
    #         'limit': 10,
    #         'nmID': nm
    #     }
    #     response = requests.get(url, headers=headers, params=data)
    #     print(response )
    #     if response.status_code == 200:
    #         data = response.json()
    #         print(data)
    #         return data
    #     else:
    #         print(f'Error: Unable to retrieve stock for product ID')
    #         return None


# Использование класса WildberriesAPI
api_key = API_price
ListOfGoods = ListOfGoods(api_key)
stock = ListOfGoods.get_product_stock(20)

api_key = 'eyJhbGciOiJFUzI1NiIsImtpZCI6IjIwMjQwMjI2djEiLCJ0eXAiOiJKV1QifQ.eyJlbnQiOjEsImV4cCI6MTcyNzgzNzc1MiwiaWQiOiJlMTc0ZGYwNS05NzEzLTQzMjEtYmQyMC1iMWMzZmUxZjUyNzgiLCJpaWQiOjI5NjE1NDE1LCJvaWQiOjczMDY2OCwicyI6MzIsInNpZCI6IjU1MDBlOWViLTk4MGMtNGI5Mi1hYWE0LWUyOWY4NzQzYjYxNCIsInQiOmZhbHNlLCJ1aWQiOjI5NjE1NDE1fQ.hJQL4g07o9GuCnfVIzVttamdtNu9Zoexu3tTmtQHg3jwpk8WBCr7oy4IlWY-3E_uNOs80NYZtiXv7b2JRfgcwg'
statistics = Statistics(api_key)
price_el = statistics.sales('2024-05-20')
price_el_2 = statistics.orders('2024-05-20')
print(price_el_2)
